<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="品类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="targetType">
              <a-input v-model="model.targetType" placeholder="请输入品类"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="targetName">
              <a-input v-model="model.targetName" placeholder="请输入名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tradevariety">
              <a-input v-model="model.tradevariety" placeholder="请输入品种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开仓趋势" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="opentrendkind">
              <a-input-number v-model="model.opentrendkind" placeholder="请输入开仓趋势" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开仓类型1：多单； 2：空单； 3：不限类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openkind">
              <a-input-number v-model="model.openkind" placeholder="请输入开仓类型1：多单； 2：空单； 3：不限类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="同一趋势下只开仓一次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openonlyone">
              <a-input-number v-model="model.openonlyone" placeholder="请输入同一趋势下只开仓一次" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开仓固定手数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fixedlots">
              <a-input-number v-model="model.fixedlots" placeholder="请输入开仓固定手数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开仓自动手数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isautolots">
              <a-input-number v-model="model.isautolots" placeholder="请输入开仓自动手数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开仓手数自动计算比率（手/万$）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lotsrates">
              <a-input-number v-model="model.lotsrates" placeholder="请输入开仓手数自动计算比率（手/万$）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="DMI趋势启动点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dmia">
              <a-input-number v-model="model.dmia" placeholder="请输入DMI趋势启动点" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="DMI趋势启动结束点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dmib">
              <a-input-number v-model="model.dmib" placeholder="请输入DMI趋势启动结束点" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="多方RSI区间小值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longrsia">
              <a-input-number v-model="model.longrsia" placeholder="请输入多方RSI区间小值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="多方RSI区间大值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longrsib">
              <a-input-number v-model="model.longrsib" placeholder="请输入多方RSI区间大值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="空方RSI区间小值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shortrsia">
              <a-input-number v-model="model.shortrsia" placeholder="请输入空方RSI区间小值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="空方RSI区间大值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shortrsib">
              <a-input-number v-model="model.shortrsib" placeholder="请输入空方RSI区间大值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="允许CCI" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="usecci">
              <a-input-number v-model="model.usecci" placeholder="请输入允许CCI" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="多单CCI阀值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longccilevel">
              <a-input-number v-model="model.longccilevel" placeholder="请输入多单CCI阀值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="多单CCI差值（>0）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longccideviation">
              <a-input-number v-model="model.longccideviation" placeholder="请输入多单CCI差值（>0）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="空单CCI阀值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shortccilevel">
              <a-input-number v-model="model.shortccilevel" placeholder="请输入空单CCI阀值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="空单CCI差值（>0）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shortccideviation">
              <a-input-number v-model="model.shortccideviation" placeholder="请输入空单CCI差值（>0）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="止损点数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stoploss">
              <a-input-number v-model="model.stoploss" placeholder="请输入止损点数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="动态止损点（波动率）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useautostoploss">
              <a-input-number v-model="model.useautostoploss" placeholder="请输入动态止损点（波动率）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="止盈点数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="takeprofit">
              <a-input-number v-model="model.takeprofit" placeholder="请输入止盈点数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="移损点数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="movesl">
              <a-input-number v-model="model.movesl" placeholder="请输入移损点数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="移盈点数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="movetp">
              <a-input-number v-model="model.movetp" placeholder="请输入移盈点数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="移损移盈时利润优先" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="profitfirstonmovesp">
              <a-input-number v-model="model.profitfirstonmovesp" placeholder="请输入移损移盈时利润优先" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="RSI超买值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rsioverbought">
              <a-input-number v-model="model.rsioverbought" placeholder="请输入RSI超买值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="RSI超卖值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rsioversold">
              <a-input-number v-model="model.rsioversold" placeholder="请输入RSI超卖值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="持仓趋势反转平仓" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="atxtrendrevers">
              <a-input-number v-model="model.atxtrendrevers" placeholder="请输入持仓趋势反转平仓" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="EMA反转平仓" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ematrendrevers">
              <a-input-number v-model="model.ematrendrevers" placeholder="请输入EMA反转平仓" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="强趋势变弱平仓" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dmistrong2weak">
              <a-input-number v-model="model.dmistrong2weak" placeholder="请输入强趋势变弱平仓" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="三色趋势反转平仓" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="trendrevers3">
              <a-input-number v-model="model.trendrevers3" placeholder="请输入三色趋势反转平仓" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="三色趋势共振" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="same3trend">
              <a-input-number v-model="model.same3trend" placeholder="请输入三色趋势共振" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="持仓趋势共振" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sameatxtrend">
              <a-input-number v-model="model.sameatxtrend" placeholder="请输入持仓趋势共振" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="DMI趋势逐渐增强" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="samestrongdmi">
              <a-input-number v-model="model.samestrongdmi" placeholder="请输入DMI趋势逐渐增强" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="DMI趋势须比较K线柱数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="samestrongdminums">
              <a-input-number v-model="model.samestrongdminums" placeholder="请输入DMI趋势须比较K线柱数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="DMI趋势差值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="samestrongdmideviation">
              <a-input-number v-model="model.samestrongdmideviation" placeholder="请输入DMI趋势差值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="EMA同方向开仓" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sameema">
              <a-input-number v-model="model.sameema" placeholder="请输入EMA同方向开仓" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="EMA同向时突破或跌破EMA线的K线柱数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sameemanums">
              <a-input-number v-model="model.sameemanums" placeholder="请输入EMA同向时突破或跌破EMA线的K线柱数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="K线柱走势同向" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="samek">
              <a-input-number v-model="model.samek" placeholder="请输入K线柱走势同向" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="比较K线柱数（值为2或3或4）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sameknums">
              <a-input-number v-model="model.sameknums" placeholder="请输入比较K线柱数（值为2或3或4）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TargetIndexForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/gongqiang/targetIndex/add",
          edit: "/gongqiang/targetIndex/edit",
          queryById: "/gongqiang/targetIndex/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>